package com.xcc.mota;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;

import com.xcc.mota.utils.Logger;

public class MainActivity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    protected void asynRun() {
        Logger.out("----------asynRun----------");

        gameView = new GameView(this);
        setContentView(gameView);
    }

    private boolean isF = true;
    private GameView gameView;

    public void onWindowFocusChanged(boolean hasFocus) {
        if (hasFocus & isF) {
            isF = false;
            asynRun();
        }
    }

    protected void onDestroy() {
        super.onDestroy();
        gameView.setRuning(false);
    }

    public void onBackPressed() {
        new AlertDialog.Builder(this)
                .setMessage("确认退出游戏")
                .setPositiveButton("取消", null)
                .setNegativeButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).create().show();
    }
}
